<?php

//控制基类

class Controller extends Smarty
{
    
    function __construct()
    {
        //smarty配置
        //使用方法来配置:
        $this->setTemplateDir('./views')
               ->setCompileDir('./runtime/views_c')
               ->setConfigDir('./configs')
               ->setCacheDir('./runtime/caches');

        // 配置 模版变量定界符
        $this->left_delimiter = LEFT_D;
        $this->right_delimiter = RIGHT_D;

        // 配置 缓存
        $this->caching = CACHING;
        // 配置 缓存时间
        $this->cache_lifetime = CACHE_LIFETIME;//开启缓存有效时间.
    }

    //跳转
    public function redirect($message, $url=null)
    {
        echo "<script>alert('{$message}')</script>";

        if (empty($url)) {
            //返回到之前的页面
            echo "<script>history.back()</script>";
        } else {
            echo "<script>location.href='{$url}'</script>";
        }

    }



    //处理在调用不存在的方法
    public function __call($fun, $params)
    {
        header("HTTP/1.0 404 not found");//非IE
        header("Status:404 not found");//IE兼容
        echo "<h1>404 NOT FOUND..</h1>";
        exit;


    }

}








